package com.wejoy.video.middle.station.data.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;

/**
 * 每个对象都需要继承的类, 用于分页
 * @author admin
 */
public class BasePage implements Serializable {
    private static final Logger LOGGER = LoggerFactory.getLogger(BasePage.class);
    private static final long serialVersionUID = -320995871886379593L;
    /** 页码 */
    private Integer pageNo;
    /** 每页大小 */
    private Integer pageSize;

    public Integer getPageNo() {
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }

    public Integer getPageSize() {
        //最大限制为5000
        if (null != pageSize && pageSize > 5000) {
            LOGGER.warn(" pageSize 过大！！！pageSize={}", pageSize);
            return 5000;
        }
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    @JsonIgnore
    public Integer getStartIndex() {
        if (pageNo == null || pageSize == null) {
            return null;
        }
        return (this.pageNo - 1) * this.pageSize;
    }
}
